define(function (require, exports, module) {
    var $ = require("jquery");
    var angular = require("angular");
    var ui = require("ui");
    require('authorize');
    require("permission");
    require("angular-route");
    require("pagination");
    require("angular-ui");
    require("angular-interceptor");
    require("plupload");
    require('../../myservice/common/nav');
    var util = require("util");
    require("./activities-service");
    require("./base-service");
    var dialog = require("dialogplus");
    require("/static_public/js/angular_directive/clipboard");
    require('global');

    var app = angular.module('app', ['ngRoute', 'ngUI', 'ngInterceptor', 'raiseFinanceActivitiesModule', 'myNav', 'raiseFinanceBaseModule', 'angular.directive.clipboard']);

    app.config(['$routeProvider', function ($routeProvider) {
        $routeProvider
            .when('/list', {templateUrl: 'activities/list.html', controller: 'RaiseFinanceActivitiesListController'})
            .when('/edit', {templateUrl: 'activities/edit.html', controller: 'RaiseFinanceActivitiesEditController'})
            .otherwise({redirectTo: '/list'});
    }]);

    /**
     * 格式化楼盘卖点
     */
    app.filter('formatDiscount', function () {
        return function (discount) {
            if (!discount) {
                return '';
            }
            var s = discount.split('##').join(',').replace(/,{2,6}/ig, ',').replace(/^,|,$/ig, '');
            return s;
        };
    });

    app.controller('RaiseFinanceActivitiesListController', ['$scope', '$routeParams', 'raiseFinanceBaseData', 'raiseFinanceActivities', function ($scope, $routeParams, raiseFinanceBaseData, raiseFinanceActivities) {
        $scope.baseData = raiseFinanceBaseData;
        $scope.activitiesSvr = raiseFinanceActivities;

        var activitiesId = $routeParams.id;
        $scope.baseData.activities_id = activitiesId;

        $scope.getActivitiesData = function (page) {
            $scope.activitiesSvr.query(page, $scope.activitiesSvr.filter.pageSize, $scope.currStatus.value, $scope.keyword);
        };
        setTimeout(function () {
            $scope.activitiesSvr.query(1, $scope.activitiesSvr.filter.pageSize, $scope.currStatus.value, $scope.keyword);
        }, 0)


        setTimeout(function () {
            // setTimeout 为了让路由先完成，防止 dom 元素闪动
            $scope.$apply(function () {
                raiseFinanceBaseData.initData();
            });
        }, 10);

        $scope.filterDataCities = [
            {value: '', areaName: '全部', selected: true},
            {value: 1, areaName: '北京'},
            {value: 1, areaName: '深圳'},
            {value: 1, areaName: '上海'},
            {value: 1, areaName: '广州'},
            {value: 1, areaName: '香港'},
        ];
        $scope.filterDataStatus = [
            {value: '', name: '全部', selected: true},
            {value: '0', name: '未上架'},
            {value: '1', name: '已上架'}
        ];

        $scope.currStatus = {};
        $scope.search = function () {
            $scope.activitiesSvr.query(1, $scope.activitiesSvr.filter.pageSize, $scope.currStatus.value, $scope.keyword);
        };

        $scope.activities = [];

        $(document).on('click', function (e) {
            if ($(e.target).is('.showqr')) {
                return;
            }
            ;
            $scope.activitiesSvr.showQR = '';
        });

        $scope.aftercopyNotify = function () {
            ui.showSucTip('复制成功');
        }
    }])

    app.controller('RaiseFinanceActivitiesEditController', ['$scope', '$routeParams', function ($scope, $routeParams) {

    }])

    angular.bootstrap(document, ['app']);
});